<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="com.sz.common.ICommonDAO" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String tmp = null;

tmp = request.getParameter("username");
String username = (tmp!=null) ? tmp : "";

tmp = request.getParameter("password");
String password = (tmp!=null) ? tmp : "";

tmp = request.getParameter("region");
String region = (tmp!=null) ? tmp : "";

tmp = request.getParameter("message");
String message = (tmp!=null) ? tmp : "";

ServletContext servletContext = request.getSession().getServletContext(); 
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
ICommonDAO dao = (ICommonDAO) context.getBean("CommonDAO");
List list = dao.queryForList("select region_id, region_name from login_region");

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>登陆系统</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="login">
	<meta http-equiv="description" content="系统登陆界面">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
  	<form name="login_form" action="login.do" method="post" onsubmit="return login_check(username,password,region)">  	
  		<table width="100%" height="300px" border="0" cellpadding="0" cellspacing="0">
  		  <tr>
  		    <td colspan="2" style="text-align:center">
  		    <img src="img/head.bmp" />
  		    </td>

  		  </tr>
  		  <tr>
  		    <td style="text-align:right" width="50%">用户名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
  		    <td style="text-align:left" width="50%">
  		      <input type="text" name="username" value="<%=username%>" size="20">
  		    </td>
  		  </tr>
  		  
  		  <tr>
  		    <td style="text-align:right">密&nbsp;&nbsp;&nbsp;&nbsp;码&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
  		    <td style="text-align:left">
  		      <input type="password" name="password" value="<%=password%>" style="width:156px">
  		    </td>
  		  </tr>
  		  
  		  <tr>
		  	<td style="text-align:right">区&nbsp;&nbsp;&nbsp;&nbsp;域&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		  	<td style="text-align:left">
				<select id="region" name="region" style="width:156px">
				  <option value="-1"></option>
				   <%
				   String value = null;
				   String text = null;
				   boolean b = false;
				   %>
				   
				   <%
				   for(int n = 0; n < list.size(); ++n) { 
					   
					   Map map = (Map)list.get(n);
					   value = map.get("REGION_ID").toString();
					   text = map.get("REGION_NAME").toString();
					   b = value.equals(region);
				   %>
				   <option <%if(b){%> selected="selected" <%}%>
				     value="<%=value%>"><%=text%>
				   </option>
				   <%}%>				   
				</select>
		  	</td>
		 </tr>
		 <tr>
		  	<td colspan="2" style="text-align:center">
		  	  <input type="submit" value="登陆" >
		  	</td>
	  	</tr>
	  	
	  	  <tr>  		    
  		    <td colspan="2" style="text-align:center">
  		      <label style="color:red"> <%=message%> </label>
  		    </td>
  		  </tr>	
  		  
  	</table>
  		
  		<!-- 
  		<P>
		  	<label>用户名</label>
		  	<input type="text" name="username" value="<%=username%>" >
	  	</P>
	  	<p>	  	
		  	<label>密码</label>	  	
		  	<input type="password" name="password" value="<%=password%>" >		  	
		  	<input type="submit" value="登陆" >
	  	</p>
	  	<p>
	  		<label> <%=message%> </label>
	  	</p>  -->
  	</form> 
  	
  	<SCRIPT LANGUAGE="JavaScript">
  		function login_check(username, password, region) {
  			var u = username.value;
  			var p = password.value;
  			if(u=="") {
  				alert("请输入用户名");
  				return false;
  			}
   			if(p=="") {
  				alert("请输入密码");
  				return false; 			
  			}

			var reg = region.value;
			if(reg < 0) {
  				alert("请选择区域");
  				return false; 	
			}
  			return true;
  			
  		}
  	
  	</SCRIPT>
  </body>
</html>
